package com.zego.wawaji.ui.store.convert;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.zego.wawaji.R;
import com.zego.wawaji.third.image.ImageLoader;
import com.zego.wawaji.ui.base.recycler.BaseRecyclerViewAdapter;
import com.zego.wawaji.ui.base.recycler.BaseRecyclerViewHolder;
import com.zego.wawaji.ui.store.bean.Store;
import com.zego.wawaji.ui.view.counter.SnappingStepper;
import com.zego.wawaji.ui.view.counter.listener.SnappingStepperValueChangeListener;
import com.zego.wawaji.wawaji_client.App;

/**
 * Created by Su on 2018/1/9.
 */
public class ConvertAdapter extends BaseRecyclerViewAdapter<Store> {
    @Override
    public int[] getItemLayouts() {
        return new int[]{R.layout.store_convert_item};
    }

    @Override
    public void onBindRecycleViewHolder(BaseRecyclerViewHolder viewHolder, int position) {
        View marginBottom = viewHolder.findViewById(R.id.margin_bottom);
        marginBottom.setVisibility(View.GONE);

        if (position == getListSize() - 1) {
            marginBottom.setVisibility(View.VISIBLE);
        }

        Store data = getItem(position);
        final TextView tvStoreNum = viewHolder.findViewById(R.id.tv_store_num);
        ImageView storeIcon = viewHolder.findViewById(R.id.store_icon);
        ImageLoader.loadCenterCrop(App.getContext(), data.getImg(), storeIcon);

        TextView storeName = viewHolder.findViewById(R.id.store_name);
        storeName.setText(data.getTitle());

        TextView storePrice = viewHolder.findViewById(R.id.store_price);
        storePrice.setText(String.valueOf(data.getWwCoinCz()));

        SnappingStepper stepper = viewHolder.findViewById(R.id.stepper);
        stepper.setOnValueChangeListener(new SnappingStepperValueChangeListener() {
            @Override
            public void onValueChange(View view, int value) {
                tvStoreNum.setText("共" + value + "件商品");
                if (listener != null) {
                    listener.onNum(value);
                }
            }
        });
    }

    @Override
    public int getRecycleViewItemType(int position) {
        return 0;
    }

    private OnChangeNum listener;

    public void setOnChaneNum(OnChangeNum listener) {
        this.listener = listener;
    }

    public interface OnChangeNum {
        void onNum(int num);
    }
}